<template>
  <div class="apply-container">
    <el-card class="apply-card">
      <div class="title">
        <span class="desc">一卡通申请</span>
        <img class="icon" src="@/assets/img/item-img/apply.png" alt="" />
      </div>
      <div class="body">
        <el-form :model="apply" label-width="80px" hide-required-asterisk>
          <el-form-item label="姓名">
            <el-input disabled v-model="apply.name"></el-input>
          </el-form-item>
          <el-form-item label="学号">
            <el-input disabled v-model="apply.studentNum"></el-input>
          </el-form-item>
          <el-form-item label="院系">
            <el-input disabled v-model="apply.department"></el-input>
          </el-form-item>
          <el-form-item label="班级">
            <el-input disabled v-model="apply.class"></el-input>
          </el-form-item>
          <el-form-item label="手机号">
            <el-input disabled v-model="apply.phone"></el-input>
          </el-form-item>
        </el-form>
        <div class="btn-container">
          <el-button type="primary" @click="applyCampus"> 提交申请 </el-button>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import commonServe from '../../api/service/common.serve'
export default {
  data() {
    return {
      id: window.sessionStorage.getItem('studentId'),
      apply: {
        name: '',
        studentNum: '',
        department: '',
        class: '',
        phone: ''
      }
    }
  },
  created() {
    this.getUserInfo()
  },
  methods: {
    // 获取用户信息
    getUserInfo() {
      commonServe
        .getStudentInfo(this.id)
        .then((res) => {
          console.log(res)
          if (res.code === 200) {
            let obj = res.data.item
            this.apply.name = obj.studentName
            this.apply.studentNum = obj.studentNum
            this.apply.department = obj.department
            this.apply.class = obj.classes
            this.apply.phone = obj.studentPhone
          } else {
            this.$message.warning('查询用户信息失败，请刷新重试')
          }
        })
        .catch((err) => {
          this.$message.warning('查询用户信息失败，请刷新重试' || err.message)
        })
    },
    // 提交申请
    applyCampus() {
      commonServe
        .applyCampus(this.id)
        .then((res) => {
          console.log(res)
          if (res.code === 200) {
            this.$message.success('已提交一卡通申请，请等待管理员审核通过')
          } else {
            this.$message.info(res.message)
          }
        })
        .catch((err) => {
          this.$message.warning(err.message)
        })
    }
  }
}
</script>

<style lang="less" scoped>
.apply-container {
  .apply-card {
    .title {
      display: flex;
      align-items: center;
      .desc {
        font-size: 30px;
        color: #3a62d7;
        letter-spacing: 10px;
        font-weight: bold;
        text-shadow: 2px 2px 5px #999;
      }
      .icon {
        width: 40px;
        height: 40px;
      }
      .icon:hover {
        transform: translateY(-5px);
        transition: 0.5s;
      }
    }
    .body {
      padding: 0 200px;
      .el-form {
        padding-top: 100px;
        .el-form-item {
          .el-input.is-disabled /deep/ .el-input__inner {
            color: #606266;
          }
        }
      }
      .btn-container {
        // padding: 0 20px;
        padding: 100px 20px 0 80px;
        .el-button {
          width: 100%;
          color: #fff;
        }
      }
    }
  }
}
</style>
